{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# On-Site Question 2 - SOLUTION\n",
    "\n",
    "## Problem\n",
    "\n",
    "** Given a list of account ID numbers (integers) which contains duplicates , find the one unique integer. (the list is guaranteed to only have one unique (non-duplicated) integer **\n",
    "\n",
    "## Requirements\n",
    "\n",
    "** Do not use built-in Python functions or methods **"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Solution\n",
    "\n",
    "This should feel very familiar to one of the problems we did in the array section of the course! We can use an [XOR](https://en.wikipedia.org/wiki/Exclusive_or) operation. The **exclusive or** operations will take two sets of bits and for each pair it will return a 1 value if **one but not both** of the bits is 1.\n",
    "\n",
    "In Python we can use the ^ symbol to perform an XOR.\n",
    "\n",
    "Now for our solution we can simply XOR all the integers in the list. We start with a unique id set to 0, then every time we XOR a new id from the list, it will change the bits. When we XOR with the same ID again, it will cancel out the earlier change.\n",
    "\n",
    "By the end, we wil be left with the ID that was unique and only appeared once!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def solution(id_list):\n",
    "    \n",
    "    # Initiate unique Id\n",
    "    unique_id = 0\n",
    "    \n",
    "    # XOR fo revery id in id list\n",
    "    for i in id_list:\n",
    "        \n",
    "        # XOR operation\n",
    "        unique_id ^= i\n",
    "    \n",
    "    return unique_id"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Good Job!"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
